package cn.zyg;

import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@EnableHystrix
public class OrderApp {
    public static void main(String[] args) {
        SpringApplication.run(OrderApp.class,args);
    }

    // 启动类就是配置类  实例化创建的对象  方法名称就是bean对象名称
    @Bean
    // 此注解即是让 Resttemplate具有负载均衡，默认是轮询
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /*
     * @Description: 配置负载均衡为随机算法
     * @Author: Director
     * @Date: 2022/7/27 17:00
     * @return: com.netflix.loadbalancer.RandomRule
     **/
    @Bean
    public RandomRule randomRule(){
        return new RandomRule();
    }

}
